package com.hj.saapp.view;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;


import com.hj.saapp.R;
import com.hj.saapp.control.fragment.base.BaseFragment;

/**
 * Created by "丁永泽" on 2016/8/12.
 */

public class BaseFragmentView extends LinearLayout{

    BaseFragment fragment;
    MultiStateView multiStateView;

    public BaseFragmentView(Fragment fragment) {
        super(fragment.getActivity(), null);
        this.fragment = (BaseFragment)fragment;
        initView();
    }

    public BaseFragmentView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView()
    {
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        LayoutParams contentParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        this.setBackgroundResource(R.color.main_bk);
        this.setOrientation(VERTICAL);
        this.setLayoutParams(params);
        LayoutInflater inflater = LayoutInflater.from(fragment.getActivity());
        View content = inflater.inflate(fragment.getLayoutByid(),null);
        multiStateView = new MultiStateView(fragment.getActivity());
        multiStateView.addView(content);
        this.addView(multiStateView,contentParams);
    }

    public void  showLoading() {

        multiStateView.setViewState(MultiStateView.VIEW_STATE_LOADING);

    }
    public void  showContent() {

        multiStateView.setViewState(MultiStateView.VIEW_STATE_CONTENT);

    }
    public void  showError() {

        multiStateView.setViewState(MultiStateView.VIEW_STATE_ERROR);

    }
    public void  showEmpty() {

        multiStateView.setViewState(MultiStateView.VIEW_STATE_EMPTY);

    }

}
